import 'package:flutter/material.dart';

import '../../base/base_chart.dart';
import 'base_pie_entity.dart';

/// 饼状图基类
///
/// [D]为饼状图数据
abstract class BasePieChartDelegate<D> extends BaseChartDelegate<D> {
  BasePieChartDelegate(
      {required this.radius,
      super.animDuration,
      super.data,
      super.gestureHandler,
      super.emptyWidgetBuilder,
      super.isDataEmpty,
      this.innerRadius = 0,
      this.sliceSpace = 0,
      this.baseMapColor = Colors.transparent,
      this.drawStartAngle = 0,
      this.labelPosition,
      required this.dataRender,
      this.labelRender})
      : assert(radius > 0),
        assert(innerRadius >= 0),
        assert(radius > innerRadius, "radius must than more innerRadius");

  /// 饼状图半径
  final double radius;

  /// 内圆半径，== 0则绘制扇形，> 0则绘制圆环
  final double innerRadius;

  /// 每个扇形之间的间距
  final double sliceSpace;

  /// 底图颜色，未设置任何饼状图数据时绘制的底图
  final Color baseMapColor;

  /// 起始绘制的角度
  final double drawStartAngle;

  /// 标签绘制位置
  final LabelPosition? labelPosition;

  /// 饼状图内容绘制器
  final BasePieDataRender dataRender;

  /// 饼状图标签绘制器
  final BasePieLabelRender? labelRender;

  @override
  void onDraw(Canvas canvas, double animProgress) {
    dataRender.onDraw(this, canvas, animProgress);
    labelRender?.onDraw(this, canvas, animProgress);
  }
}

/// 饼状图内容绘制器
mixin BasePieDataRender<C extends BasePieChartDelegate> {
  void onDraw(C chart, Canvas canvas, double animProgress);
}

/// 饼状图标签绘制器
mixin BasePieLabelRender<C extends BasePieChartDelegate> {
  /// 绘制标签内容，此时[BasePieChartEntity.drawStartAngle]、[BasePieChartEntity.drawSweepAngle]、[BasePieChartEntity.drawRadius]已就绪，
  /// 可基于此数据绘制标签
  void onDraw(C chart, Canvas canvas, double animProgress);
}
